***** RUN DO_MASTER.do ***** do "$Do_files\DO_MASTER.do"

global program "OA_TableB312"
cap log close
cap log using "$Log_files\log_$program$today", replace

**** REPLICATION OF TABLE B.3.12 ****

clear all
set mem 2g
set more off

// Import data

use $Data\data_news_voting, clear

// Get controls

global ctrl_base	"sh_lde lpop_A sh_F sh_F_new sh_cspsup sh_sec sh_ter lmean_reink lmean_reink2 charact_altitude charact_altitude_std sh_active sh_young sh_prot sh_M com_property mk" // 
global ctrl_plus	"mean_votation lcrSR_F_N"
global fe			"charact_agglo"
global fe_iv		"I_charact_agglo_*"
global cluster		"charact_agglo"

// Column 1
		
reghdfe oui instr_dev_dcom /// 		
	$ctrl_plus ///
	$ctrl_base ///
	if sample_hq00dstr==1, ///
	absorb($fe) cluster($cluster) keepsing	
estimates store RF_dcom_dev_ctrl

// Column 2

reghdfe endog_mk instr_dev_dcom /// 		
	$ctrl_plus ///
	$ctrl_base ///
	if sample_hq00dstr==1, ///
	absorb($fe) cluster($cluster) keepsing	
estimates store FS_dcom_dev_ctrl
test instr_dev_dcom
estadd scalar F_fs=r(F)
		
// Column 3
		
ivreg2 oui (endog_mk = instr_dev_dcom) ///
	$ctrl_plus ///
	$ctrl_base ///
	$fe_iv ///
	if sample_hq00dstr==1, ///
	cluster($cluster) first partial($fe_iv)	
estimates store TSLS_dcom_dev_ctrl

// Column 4
		
reghdfe oui instr_np_mk /// 		
	$ctrl_plus ///
	$ctrl_base ///
	if sample_hq00dstr==1, ///
	absorb($fe) cluster($cluster) keepsing	
estimates store RF_np_ctrl

// Column 5

reghdfe endog_mk instr_np_mk /// 		
	$ctrl_plus ///
	$ctrl_base ///
	if sample_hq00dstr==1, ///
	absorb($fe) cluster($cluster) keepsing	
estimates store FS_np_ctrl
test instr_np_mk
estadd scalar F_fs=r(F)
		
// Column 6
		
ivreg2 oui (endog_mk = instr_np_mk) ///
	$ctrl_plus ///
	$ctrl_base ///
	$fe_iv ///
	if sample_hq00dstr==1, ///
	cluster($cluster) first partial($fe_iv)	
estimates store TSLS_np_ctrl

// Labels

la var endog_mk 			"Crime News Exposure ($\mathtt{CNE}$)"
la var instr_dev_dcom 		"[0.1em] Relative Distance $ \times \mathtt{\Delta HQC} $"   
la var instr_np_mk 			"[0.1em] News pressure on $ \mathtt{HQC} $ days ($ \mathtt{HQNP} $)"   
la var lcrSR_F_N 			"[0.1em] Local $ \mathtt{CPD} $"
la var mean_votation 		"[0.1em] Past Vote Outcomes"

// Table For Paper
	
estout RF_dcom_dev_ctrl FS_dcom_dev_ctrl TSLS_dcom_dev_ctrl RF_np_ctrl FS_np_ctrl TSLS_np_ctrl ///
	using "$Results\\$program.tex", replace style(tex) type label	///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(N r2_a F_fs, lab("Observations" "Adjusted $ R^2 $" "First-stage F-statistic") fmt(0 3 2)) ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels($^c$ .1 $^b$ .05 $^a$ .01) ///
	keep(endog_mk lcrSR_F_N mean_votation instr_dev_dcom instr_np_mk) /// 
	order(endog_mk lcrSR_F_N mean_votation instr_dev_dcom instr_np_mk) ///	
	title(News and voting: Alternative instruments) ///		
	varlabels(instr_dev6_dist "[1em] \% foreign crime: HQ areas (dev.) $ \times $ distance") ///
	prehead("\begin{table}[!h]" ///
	"\centering" ///
	"\resizebox {1\textwidth}{!}{%" ///
	"\begin{threeparttable}" ///
	"\begin{footnotesize}" ///
	"\caption{\small{@title}\label{$program}}" ///
	"\begin{tabular*}{\columnwidth}{@{\extracolsep{\stretch{1}}}l*{@M}{c}@{}}" ///
	"\hline" "\hline" ///	
	"\\" ///
	"Instrument			&\multicolumn{3}{c}{Relative Distance $ \times \mathtt{\Delta HQC} $} 	&\multicolumn{3}{c}{News pressure on $ \mathtt{HQC} $ days} \\" ///
	"					\cmidrule(lr){2-4}												\cmidrule(lr){5-7} 							" ///
	"Specification		&\multicolumn{1}{c}{RF}			&\multicolumn{1}{c}{FS}			&\multicolumn{1}{c}{2SLS}		&\multicolumn{1}{c}{RF}		&\multicolumn{1}{c}{FS}		&\multicolumn{1}{c}{2SLS} \\" ///
	"					\cmidrule(lr){2-2} 				\cmidrule(lr){3-4}				\cmidrule(lr){5-5}				\cmidrule(lr){6-7}" ///
	"Dependent Variable &\multicolumn{1}{c}{\%Yes} 		&\multicolumn{1}{c}{$ \mathtt{CNE} $}		&\multicolumn{1}{c}{\%Yes}		&\multicolumn{1}{c}{\%Yes} 		&\multicolumn{1}{c}{$ \mathtt{CNE} $}		&\multicolumn{1}{c}{\%Yes}	\\" ///
	"					\cmidrule(lr){2-4}												\cmidrule(lr){5-7} 							" ///
	"					&\multicolumn{1}{c}{(1)} 		&\multicolumn{1}{c}{(2)}  		&\multicolumn{1}{c}{(3)} 		&\multicolumn{1}{c}{(4)}  	&\multicolumn{1}{c}{(5)} &\multicolumn{1}{c}{(6)} \\") ///
	posthead("\hline" ///
	"\\") ///
	prefoot("\\" ///
	"\hline") ///
	postfoot("\hline" "\hline" ///
	"\end{tabular*}" /// 
	"\end{footnotesize}" ///
	"\begin{tablenotes}[normal,flushleft]" ///
	"\begin{scriptsize}" ///
	"\item \emph{Notes}:" /// 
	"The unit of observation is a municipality. " /// 
	"Standard errors clustered at agglomeration level in parentheses. " ///
	"{$^c$} significant at 10\%; {$^b$} significant at 5\%; {$^a$} significant at 1\%. " /// 
	"Columns (1) to (3) show estimates with the instrument for $ \mathtt{CNE} $ computed as short-run deviation of $ \mathtt{CPD} $ in headquarter areas aggregated at municipality level " ///
	"using the relative distance between the municipality and the nearest headquarter as weights. " ///
	"Columns (4) to (6) present estimates where $ \mathtt{CNE} $ is instrumented by news pressure on HQ crime days. " ///
	"i.e. by weighting the events (crimes) by the news space (i.e. the remaining news time) on the crime day for each of the newspapers." ///
	"All regressions include the full vector of controls of Table \ref{Main_Table2}. " ///
	"" ///
	"\end{scriptsize}" ///
	"\end{tablenotes}" ///
	"\end{threeparttable}}" ///
	"\end{table}")

cap log close
